<%if (t.isProtocol == 1) {%>
        ${g.copyright!}
<%}%>
package ${g.codePackage}.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.stylefeng.guns.core.common.annotion.BussinessLog;
import cn.stylefeng.guns.core.common.constant.dictmap.DeleteDict;
import cn.stylefeng.guns.core.common.constant.factory.ConstantFactory;
import cn.stylefeng.guns.core.common.exception.BizExceptionEnum;
import cn.stylefeng.guns.core.common.page.LayuiPageFactory;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import cn.stylefeng.guns.core.shiro.ShiroKit;
import ${g.codePackage}.entity.${g.entityName};
import ${g.codePackage}.entity.dictmap.${g.entityName}Dict;
import ${g.codePackage}.service.${g.entityName}Service;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * ${g.name}控制器
 *
 * @author ${g.author}
 * @Date ${g.date}
 */
@Controller
@RequestMapping("/${strutil.toLowerCase(g.entityName)}")
public class ${g.entityName}Controller extends BaseController {

    private String PREFIX = "/${g.prefix}/${strutil.toLowerCase(g.entityName)}/";

    @Autowired
    private ${g.entityName}Service ${g.lowerEntityName}Service;

    /**
     * 跳转到${g.name}列表首页
     *
	 * @author ${g.author}
	 * @Date ${g.date}
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "${strutil.toLowerCase(g.entityName)}.html";
    }

    /**
     * 跳转到添加${g.name}
     *
	 * @author ${g.author}
	 * @Date ${g.date}
     */
    @RequestMapping("/goto_add")
    public String ${g.lowerEntityName}Add() {
        return PREFIX + "${strutil.toLowerCase(g.entityName)}_add.html";
    }

    /**
     * 跳转到修改${g.name}
     *
	 * @author ${g.author}
	 * @Date ${g.date}
     */
    @RequestMapping("/goto_update/{id}")
    public String ${g.lowerEntityName}Update(@PathVariable Long id, Model model) {
        ${g.entityName} ${g.lowerEntityName} = this.${g.lowerEntityName}Service.getById(id);
        model.addAttribute("${strutil.toLowerCase(g.entityName)}", ${g.lowerEntityName});
        LogObjectHolder.me().set(${g.lowerEntityName});
        return PREFIX + "${strutil.toLowerCase(g.entityName)}_edit.html";
    }
	
    /**
     * 获取${g.name}列表
     *
	 * @author ${g.author}
	 * @Date ${g.date}
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        Page<Map<String, Object>> list = this.${g.lowerEntityName}Service.list(condition);
        //Page<Map<String, Object>> wrap = new ${g.entityName}Wrapper(list).wrap();
        return LayuiPageFactory.createPageInfo(list);
    }

    /**
     * 新增${g.name}
     *
	 * @author ${g.author}
	 * @Date ${g.date}
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    <%if (t.isLog == 1) {%>
    @BussinessLog(value = "新增${g.name}", key = "${g.idName}", dict = ${g.entityName}Dict.class)
    <%}%>
    public Object add(${g.entityName} ${g.lowerEntityName}) {
        this.${g.lowerEntityName}Service.save(${g.lowerEntityName});
        return SUCCESS_TIP;
    }

    /**
     * 删除${g.name}
     *
	 * @author ${g.author}
	 * @Date ${g.date}
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    <%if (t.isLog == 1) {%>
    @BussinessLog(value = "删除${g.name}", key = "${g.idName}", dict = DeleteDict.class)
    <%}%>
    public Object delete(@RequestParam Long ${g.idName}) {
        this.${g.lowerEntityName}Service.removeById(${g.idName});
        return SUCCESS_TIP;
    }

    /**
     * 修改${g.name}
     *
	 * @author ${g.author}
	 * @Date ${g.date}
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    <%if (t.isLog == 1) {%>
    @BussinessLog(value = "修改${g.name}", key = "${g.idName}", dict = ${g.entityName}Dict.class)
    <%}%>
    public Object update(${g.entityName} ${g.lowerEntityName}) {
        this.${g.lowerEntityName}Service.updateById(${g.lowerEntityName});
        return SUCCESS_TIP;
    }

}
